package com.framework.service.module.user.impl;

import com.framework.common.model.response.R;
import com.framework.common.util.other.NumeralUtil;
import com.framework.mapper.module.user.RightsMapper;
import com.framework.model.module.user.Rights;
import com.framework.model.system.SystemUser;
import com.framework.service.base.BaseService;
import com.framework.service.module.user.RightsService;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 龘鵺
 * @version 1.0
 * @className com.framework.service.module.user.impl.RightsServiceImpl
 * @description 用户权限业务接口实现类
 * @datetime 2024-05-14 09:59:18
 */
@Service("rightsServiceImpl")
public class RightsServiceImpl extends BaseService implements RightsService {
    private Logger log = LoggerFactory.getLogger(RightsServiceImpl.class);
    @Autowired
    private RightsMapper rightsMapper;

    /**
     * @param id 1 编号
     * @return com.framework.model.module.user.Rights
     * @title 根据编号查询用户权限
     * @description 根据编号查询用户权限
     * @author 龘鵺
     * @datetime 2024-05-14 09:59:18
     * @version 1.0
     */
    @Override
    public Rights getByIdParam(Long id) {
        Rights row = new Rights();
        row.setId(id);
        row.setGtaeOperaterStatus(NumeralUtil.POSITIVE_ONE);
        Rights p = rightsMapper.selectByParam(row);
        if (p == null) {
            return new Rights();
        }
        return p;
    }

    /**
     * @param row 1 用户权限类
     * @return com.framework.common.model.response.R
     * @title 新增用户权限
     * @description 新增用户权限
     * @author 龘鵺
     * @datetime 2024-05-14 09:59:18
     * @version 1.0
     */
    @Override
    @Transactional
    public R<?> save(Rights row) {
        SystemUser systemUser = getUser();
        Long userId = systemUser.getId();
        Date date = new Date();
        row.setCreateId(userId);
        row.setCreateTime(date);
        row.setOperaterId(userId);
        row.setOperaterTime(date);
        row.setOperaterStatus(NumeralUtil.POSITIVE_ONE);
        rightsMapper.insertSelective(row);
        return R.ok();
    }

    /**
     * @param row 1 用户权限类
     * @return com.framework.common.model.response.R
     * @title 编辑用户权限
     * @description 编辑用户权限
     * @author 龘鵺
     * @datetime 2024-05-14 09:59:18
     * @version 1.0
     */
    @Override
    @Transactional
    public R<?> edit(Rights row) {
        Rights queryParam = rightsMapper.selectByPrimaryKey(row.getId());
        if (queryParam == null) {
            return R.fail("编辑信息不存在!");
        }
        SystemUser systemUser = getUser();
        Long userId = systemUser.getId();
        Date date = new Date();
        row.setOperaterTime(date);
        row.setOperaterId(userId);
        row.setOperaterStatus(NumeralUtil.POSITIVE_TWO);
        rightsMapper.updateByPrimaryKeySelective(row);
        return R.ok();
    }

    /**
     * @param id 1 编号
     * @return com.framework.common.model.response.R
     * @title 删除用户权限
     * @description 删除用户权限
     * @author 龘鵺
     * @datetime 2024-05-14 09:59:18
     * @version 1.0
     */
    @Override
    @Transactional
    public R<?> delete(Long id) {
        Rights row = new Rights();
        SystemUser systemUser = getUser();
        Long userId = systemUser.getId();
        Date date = new Date();
        row.setId(id);
        row.setOperaterTime(date);
        row.setOperaterId(userId);
        row.setOperaterStatus(NumeralUtil.NEGATIVE_ONE);
        rightsMapper.delete(row);
        return R.ok();
    }

    /**
     * @param idList 1 编号集合
     * @return com.framework.common.model.response.R
     * @title 批量删除用户权限
     * @description 批量删除用户权限
     * @author 龘鵺
     * @datetime 2024-05-14 09:59:18
     * @version 1.0
     */
    @Override
    @Transactional
    public R<?> batchDeleteList(List<Long> idList) {
        Rights row = new Rights();
        SystemUser systemUser = getUser();
        Long userId = systemUser.getId();
        Date date = new Date();
        row.setIdList(idList);
        row.setOperaterTime(date);
        row.setOperaterId(userId);
        row.setOperaterStatus(NumeralUtil.NEGATIVE_ONE);
        //rightsMapper.deleteList(row);
        return R.ok();
    }

    /**
     * @param row 1 用户权限类
     * @return java.util.List<com.framework.model.module.user.Rights>
     * @title 查询用户权限集合
     * @description 查询用户权限集合
     * @author 龘鵺
     * @datetime 2024-05-14 09:59:18
     * @version 1.0
     */
    @Override
    public List<Rights> findByList(Rights row) {
        row.setGtaeOperaterStatus(NumeralUtil.POSITIVE_ONE);
        List<Rights> list = rightsMapper.findByList(row);
        return list;
    }

    /**
     * @param row 1 用户权限类
     * @return com.framework.common.model.response.R
     * @title 分页查询用户权限列表
     * @description 分页查询用户权限列表
     * @author 龘鵺
     * @datetime 2024-05-14 09:59:18
     * @version 1.0
     */
    @Override
    public R<?> findParamPageList(Rights row) {
        row.setGtaeOperaterStatus(NumeralUtil.POSITIVE_ONE);
        int count = rightsMapper.findPageListCount(row);
        if (count == NumeralUtil.POSITIVE_ZERO) {
            return R.ok();
        }
        List<Rights> list = rightsMapper.findPageList(row);
        return R.ok(list, count);
    }
}